home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / stterm / read_tty.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  975b  |  64 lines

  1. /* get chars from rs232 and display them */
  2.  
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include "const.h"
  6.  
  7. #ifdef __STDC__
  8. void cleanup(int foo)
  9. #else
  10. int cleanup()
  11. #endif
  12. {
  13.   fprintf(stderr, "reader stopped\n");
  14.   fflush(stderr);
  15.  
  16.   exit(0);
  17. }
  18.  
  19. #ifdef __GNUC__
  20. volatile
  21. #endif
  22.     char suspended = 0;
  23.  
  24.  
  25. #ifdef __STDC__
  26. void toggle(int foo)
  27. #else
  28. int toggle()
  29. #endif
  30. {
  31.     suspended ^= (char)1;
  32. }
  33.  
  34.  
  35. #define NCHRS 16
  36. char err_buf[BUFSIZ];
  37.  
  38. main()
  39. {
  40.   char chrs[NCHRS];
  41.   register short i, n;
  42.   register char *p;
  43.   
  44.   signal(SIGINT,  cleanup);
  45.   signal(SIGQUIT, cleanup);
  46.   signal(SIGTERM, cleanup);
  47.   signal(SIGALRM, toggle);    /* writer signals us to toggle suspend */
  48.   
  49.   setbuf(stderr, err_buf);
  50.  
  51.   fprintf(stderr, "reader started\n");
  52.   fflush(stderr);
  53.  
  54.   while (TRUE) {
  55.       while(suspended)    /* while we are doing do_shell() */
  56.       pause();
  57.       
  58.       n = read(0, chrs, (int)NCHRS);
  59.       for(p = chrs, i = n; i ; --i)
  60.       *p++ &= (char)0177;
  61.       write(1, chrs, n);
  62.   }
  63. }
  64.